package ks.server.processor;

import ks.framework.common.Message;
import ks.framework.communicator.Communicator;
import ks.framework.debug.Debug;
import ks.server.controllers.ChatController;
import ks.server.controllers.IconAddController;
import ks.server.controllers.IconListController;
import ks.server.controllers.LoginController;
import ks.server.controllers.LogoutController;

/**
 * Server-side processor of messages received from client.
 * <p>
 * You will need to replace this code with something more meaningful. I would
 * suggest a chain-of-responsibility pattern, as we will discuss in class.
 * 
 * @author George Heineman
 */
public class Processor  {
	
	/** Agent who knows how to communicate back to client(s). */
	Communicator com;
	
	public Processor (Communicator com) {
		this.com = com;
	}
	
	public boolean process(Message m) {

		Debug.println("Received:" + m.toString());

		// replace with something meaningful
		// hack. FIX.
		if (m.getName().equals ("chat")) {
			return new ChatController(com).process(m);
		}
		
		if (m.getName().equals ("login")) {
			return new LoginController(com).process(m);
		}
		
		if (m.getName().equals ("logout")) {
			return new LogoutController(com).process(m);
		}
		
// BEGIN-EXAMPLE
		if (m.getName().equals("icon-list")) {
			return new IconListController(com).process(m);
		}
		if (m.getName().equals("icon-add")) {
			return new IconAddController(com).process(m);
		}
		
// END-EXAMPLE
		
		// return false if we have no idea how to process this message.
		return false;
	}

}
